//----------------------------------------------------------------------------------------
// @Project Includes
#include "includes.h"

//----------------------------------------------------------------------------------------
// @Local Macro Define in the module

//----------------------------------------------------------------------------------------
// @Local Type defines in the module

//----------------------------------------------------------------------------------------
// @Global Variables define in the module

//----------------------------------------------------------------------------------------
// @Prototypes of functions in the module

//========================================================================================
/**
 * @brief  c printf 
 * @param  none
 * @return none
 * @note   none
 */ 
int fputc(int ch, FILE *f)
{
	#if DEBUG_EN == 1
		drv_usart_sendData(DEBUG_UART, (uint8_t *)&ch, 1);
	#endif
    return ch;
}

/**
 * @brief  printf the sys reset record
 * @param  none
 * @return none
 * @note   none
 */ 
void drv_debug_rstRecord(void)
{
    if (RCC_GetFlagStatus(RCC_CTRLSTS_FLAG_IWDGRSTF) != RESET)
    {
        SYSTEM_DEBUG("SYS:<< IWDG reset.\r\n");
    }
    if (RCC_GetFlagStatus(RCC_CTRLSTS_FLAG_PINRSTF) != RESET)
    {
        SYSTEM_DEBUG("SYS:<< PIN reset.\r\n");
    }
    if (RCC_GetFlagStatus(RCC_CTRLSTS_FLAG_PORRSTF) != RESET)
    {
        SYSTEM_DEBUG("SYS:<< POR reset.\r\n");
    }
    if (RCC_GetFlagStatus(RCC_CTRLSTS_FLAG_SFTRSTF) != RESET)
    {
        SYSTEM_DEBUG("SYS:<< SFT reset.\r\n");
    }	
    if (RCC_GetFlagStatus(RCC_CTRLSTS_FLAG_WWDGRSTF) != RESET)
    {
        SYSTEM_DEBUG("SYS:<< WWDG reset.\r\n");
    }	
	
    /* Clear reset flags */
    RCC_ClrFlag();

}

/**
 * @brief  printf the var
 * @param  none
 * @return none
 * @note   none
 */ 
void drv_debug_var(void)
{
		g_stcVar.u32runTimes++;
    if(g_stcVar.stcUpg.state == OTA_STATE_IDLE)
		{
		SYSTEM_DEBUG("SYS:<< var WorkStat = %d u32balStat = 0x%08x ChangIn = %d LoadIn = %d u32runTimes= %d m_SleepWaitTime = %d \r\n",
	               g_stcState.enstate,g_stcVar.u32balStat,srv_signal_getChargeIn(),srv_signal_getLoadIn(),g_stcVar.u32runTimes ,g_stcVar.u16sleepWaitTime);
		SYSTEM_DEBUG("SYS:<< var unProtRank3 = 0x%08x unProtRank2 = 0x%08x unProtRank1 = 0x%08x u32cmdBal = 0x%04x \r\n",
	               g_stcVar.unProtRank3.dword,g_stcVar.unProtRank2.dword,g_stcVar.unProtRank1.dword,g_stcVar.u32cmdBal);
		SYSTEM_DEBUG("SYS:<< var bchgMosCtl = %d ,bdsgMosCtl = %d  bchgAfeMosCtl= %d bdsgAfeMosCtl= %d\r\n",
	               g_stcVar.bchgMosCtl,g_stcVar.bdsgMosCtl,g_stcVar.bchgAfeMosCtl,g_stcVar.bdsgAfeMosCtl);
	
		SYSTEM_DEBUG("SYS:<< var CELL00 = %d CELL01 = %d CELL02 = %d CELL03 = %d CELL04 = %d \r\n",
	              g_stcVar.u16cellVolt[0],g_stcVar.u16cellVolt[1],g_stcVar.u16cellVolt[2],g_stcVar.u16cellVolt[3],g_stcVar.u16cellVolt[4]);
		SYSTEM_DEBUG("SYS:<< var CELL05 = %d CELL06 = %d CELL07 = %d CELL08 = %d CELL09 = %d \r\n",
	              g_stcVar.u16cellVolt[5],g_stcVar.u16cellVolt[6],g_stcVar.u16cellVolt[7],g_stcVar.u16cellVolt[8],g_stcVar.u16cellVolt[9]);
		SYSTEM_DEBUG("SYS:<< var CELL10 = %d CELL11 = %d CELL12 = %d CELL13 = %d CELL14 = %d \r\n",
	              g_stcVar.u16cellVolt[10],g_stcVar.u16cellVolt[11],g_stcVar.u16cellVolt[12],g_stcVar.u16cellVolt[13],g_stcVar.u16cellVolt[14]);
		SYSTEM_DEBUG("SYS:<< var CELL15 = %d CELL16 = %d CELL17 = %d CELL18 = %d CELL19 = %d \r\n",
	              g_stcVar.u16cellVolt[15],g_stcVar.u16cellVolt[16],g_stcVar.u16cellVolt[17],g_stcVar.u16cellVolt[18],g_stcVar.u16cellVolt[19]);	
	
		SYSTEM_DEBUG("SYS:<< var Total Vol = %dmV Total Cur = %dmA u32trueValue= %d u32displayValue= %d\r\n",
		            g_stcVar.u32totalSumVolt ,g_stcVar.i32avgCurrent,g_stcSoc.stcdata.u32trueValue,g_stcSoc.stcdata.u32displayValue);								
		SYSTEM_DEBUG("SYS:<< var Temp0= %d Temp1= %d Temp2= %d Temp3= %d \r\n",
		            g_stcVar.i8cellTemp[0],g_stcVar.i8cellTemp[1],g_stcVar.i8cellTemp[2],g_stcVar.i8cellTemp[3]);
								
		SYSTEM_DEBUG("SYS:<< var mosTemp= %d ambTemp= %d \r\n",g_stcVar.i8mosTemp,g_stcVar.i8ambTemp);
		
		SYSTEM_DEBUG("SYS:<< var AFE_bstatus1= 0x%02x AFE_bstatus2= 0x%02x AFE_flag1= 0x%02x AFE_flag2= 0x%02x \r\n",
		            g_stcAfeReg.bstatus1.byte,g_stcAfeReg.bstatus2.byte,g_stcAfeReg.flag1.byte,g_stcAfeReg.flag2.byte);
	
//		SYSTEM_DEBUG("SYS:<< var g_stcVar.u16cbatVol = %d g_stcVar.u16vbatVol = %d Up = %d mV u8hwAddress = %d \r\n\r\n",g_stcVar.u16cbatVol ,g_stcVar.u16vbatVol,g_stcVar.i16upVol,DI_DET_READ());
    }
}
// =======================================================================================
// End of file.
// =======================================================================================
